package com.hu.zhcc.shiro.controller.HealthIntervention;

import com.hu.zhcc.common.entity.Page;
import com.hu.zhcc.shiro.entity.bo.HealthIntervention.Indexmanagement;
import com.hu.zhcc.shiro.service.HealthIntervention.IndexmanagementService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/indexManage")
public class IndexmanagementController {
    @Autowired
    private IndexmanagementService service;


    @GetMapping("")
    public ResponseEntity<Page<Indexmanagement>> findAllList(String indexName, int offset , int limit){
        Map map = new HashMap();
        if(!StringUtils.isBlank(indexName)){
            map.put("indexName",indexName);
        }
        Page<Indexmanagement> indexmanagementPage = service.selectPageList(map, offset, limit);
        return ResponseEntity.ok(indexmanagementPage);
    }

    //添加信息
    @PostMapping("")
    public int addIndex(@RequestBody Indexmanagement indexmanagement){
        return service.insertSelective(indexmanagement);
    }

    //根据编号查询需要修改的数据信息
    @GetMapping("/{id}")
    public ResponseEntity<Indexmanagement> selectAllIndex(@PathVariable("id") int id){
        Indexmanagement indexmanagement = service.selectByPrimaryKey(id);
        System.out.println(indexmanagement);
        return ResponseEntity.ok(indexmanagement);
    }

    //修改信息
    @PutMapping("")
    public int upIndex(@RequestBody Indexmanagement indexmanagement){
        return service.updateByPrimaryKeySelective(indexmanagement);
    }
}
